package com.ruoyi.web.controller.system;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.ResponseData;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SalesInventory;
import com.ruoyi.system.service.ISalesInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售库存Controller
 * 
 * @author ruoyi
 * @date 2022-10-18
 */
@Api(value = "销售库存",tags = "销售库存")
@ApiSupport(author = "ruoyi",order = 10)
@RestController
@RequestMapping("/system/inventory")
public class SalesInventoryController extends BaseController
{
    @Autowired
    private ISalesInventoryService salesInventoryService;

    /**
     * 查询销售库存列表
     */
    @ApiOperation(value = "查询销售库存列表",notes = "查询销售库存列表")
    @ApiOperationSupport(order = 10)
//    @PreAuthorize("@ss.hasPermi('system:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo<SalesInventory> list(SalesInventory salesInventory)
    {
        startPage();
        List<SalesInventory> list = salesInventoryService.selectSalesInventoryList(salesInventory);
        return getDataTable(list);
    }

    /**
     * 导出销售库存列表
     */
    @ApiOperation(value = "导出销售库存列表",notes = "导出销售库存列表")
    @ApiOperationSupport(order = 20)
    @PreAuthorize("@ss.hasPermi('system:inventory:export')")
    @Log(title = "销售库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalesInventory salesInventory)
    {
        List<SalesInventory> list = salesInventoryService.selectSalesInventoryList(salesInventory);
        ExcelUtil<SalesInventory> util = new ExcelUtil<SalesInventory>(SalesInventory.class);
        util.exportExcel(response, list, "销售库存数据");
    }

    /**
     * 获取销售库存详细信息
     */
    @ApiOperation(value = "获取销售库存详细信息",notes = "获取销售库存详细信息")
    @ApiOperationSupport(order = 30)
    @PreAuthorize("@ss.hasPermi('system:inventory:query')")
    @GetMapping(value = "/{id}")
    public ResponseData<SalesInventory> getInfo(@PathVariable("id") Long id)
    {
        return ResponseData.success(salesInventoryService.selectSalesInventoryById(id));
    }

    /**
     * 新增销售库存
     */
    @ApiOperation(value = "新增销售库存",notes = "新增销售库存")
    @ApiOperationSupport(order = 40,ignoreParameters = {"salesInventory.id"})
//    @PreAuthorize("@ss.hasPermi('system:inventory:add')")
    @Log(title = "销售库存", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public ResponseData add(@RequestBody @Valid @ApiParam(required=true) SalesInventory salesInventory)
    {
        int i = salesInventoryService.insertSalesInventory(salesInventory);
        if(i>0){
            //返回主键
            return ResponseData.success(salesInventory.getId());
        }else{
            return ResponseData.error();
        }
    }

    /**
     * 修改销售库存
     */
    @ApiOperation(value = "修改销售库存",notes = "修改销售库存")
    @ApiOperationSupport(order = 50)
    @PreAuthorize("@ss.hasPermi('system:inventory:edit')")
    @Log(title = "销售库存", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public ResponseData edit(@RequestBody @Valid @ApiParam(required=true) SalesInventory salesInventory)
    {
        int i = salesInventoryService.updateSalesInventory(salesInventory);
        if(i>0){
            //返回主键
            return ResponseData.success(salesInventory.getId());
        }else{
            return ResponseData.error();
        }
    }

    /**
     * 删除销售库存
     */
    @ApiOperation(value = "删除销售库存",notes = "删除销售库存")
    @ApiOperationSupport(order = 60)
    @PreAuthorize("@ss.hasPermi('system:inventory:remove')")
    @Log(title = "销售库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseData remove(@PathVariable Long[] ids)
    {
        //return toResult(salesInventoryService.deleteSalesInventoryByIds(ids));
        //逻辑删除
        return toResult(salesInventoryService.setDeleteByIds(ids));
    }

    /**
     * 查询销售库存列表---不进行分页
     */
    @ApiOperation(value = "查询销售库存列表---不进行分页",notes = "查询销售库存列表---不进行分页")
    @ApiOperationSupport(order = 70)
    @PreAuthorize("@ss.hasPermi('system:inventory:list')")
    @PostMapping("/getDataList")
    public ResponseData<List<SalesInventory>> getDataList(@RequestBody SalesInventory salesInventory)
    {
        List<SalesInventory> list = salesInventoryService.selectSalesInventoryList(salesInventory);
        return ResponseData.success(list);
    }
}
